
<template>
    <div class="allSort">
        <div class="sortMenu clearfix">
            <ul class="sortMenu-ul" >
                <li class="cell" v-for="(item,index)  in dataList">
                    <!--default:'1',// 1 是办公用品 #e9b778 2 是凭证请领 #83d16f-->
                    <p v-if="type==='1'"@click="selectType(index)" v-bind:class="{'onoffice':flag==index,'customName':flag!=index}"
                      >{{item.name}}</p>
                    <p v-else @click="selectType(index)" v-bind:class="{'onvoucher':flag==index,'customName':flag!=index}">{{item.name}}</p>
                </li>
            </ul>
            <div v-if="dataList.length>10" class="all" @click="showTankuang">
                <img src="../assets/type_more.png" alt="">
            </div>
            <div v-if="dataList.length>10" v-show="subitemsExpanded" class="pull-down">
                <ul class="pull-down-sort">
                    <div @click="closeType" style="color:#595959; font-size: 0.25rem;background-color: #f7f7f7;width: 100%;text-align: left;padding: .2rem;">类型</div>
                    <li class="pull-down-sort" v-for="(item,index) in dataList">
                        <p v-if="type==='1'"@click="selectType(index)" v-bind:class="{'onoffice':flag==index,'customName':flag!=index}" style="">{{item.name}}</p>
                        <p v-else @click="selectType(index)" v-bind:class="{'onvoucher':flag==index,'customName':flag!=index}">{{item.name}}</p>
                    </li>
                </ul>
            </div>
        </div>
    </div>

</template>

<script>
    export default {
        name: "typeSelectComponent",

        data() {
            return {
                flag:0,
                subitemsExpanded: false,

            };
        },

        props: {
            dataList: {
                type: Array,
                default() {
                    return []
                }
            },
            type:{

                default:'1',// 1 是办公用品 #e9b778 2 是凭证请领 #83d16f
            },

        },
        methods:{
            closeType()
            {
                this.subitemsExpanded=false;

            },
            showTankuang()
            {
                this.subitemsExpanded=!this.subitemsExpanded;
                this.$emit('showTankuang'); //主动触发selectHead方法，'123'为向父组件传递的数据


            },
            selectType(index)
            {
                this.flag=index;
                this.subitemsExpanded=false;
                this.$emit('selectType',this.dataList[index]); //主动触发selectHead方法，'123'为向父组件传递的数据


            }


        },

    }
</script>

<style lang="scss">
    /*default:'1',// 1 是办公用品 #e9b778 2 是凭证请领 #83d16f */

    .onoffice{

        color:#e9b778;
    }
    .onvoucher{

        color:#83d16f;
    }

    .customName{
        color:#595959;

    }
    .sortMenu{
        width: 100%;
        background-color:#fff;
        overflow-x: scroll;
        -webkit-overflow-x: scroll;
    }
    .sortMenu::-webkit-scrollbar{
        width: 0;
        height: 0;
        background-color: #fff;
    }
    .sortMenu-ul {
        min-width:500px;
        display: flex;
        justify-content: flex-start;
    }
    .sortMenu .cell{
        display: inline-block;
        font-size: 0.25rem;
        margin: 0px 1em;
        height: 40px;
        line-height: 40px;
        text-align: center;
        position: relative;
        text-overflow: ellipsis;
        word-break: keep-all;
    }
    .sortMenu .cell.special a{
        color: #ff474c;
    }
    .sortMenu .cell.special:before {
        content: '';
        height: 2px;
        width: 100%;
        background: #ff474c;
        position: absolute;
        bottom: 0px;
    }
    .sortMenu .all{
        right: 0;
        top: 0;
        height: 35px;
        width: 35px;
        position: absolute;
        background: #fff;
        z-index: 110;
        display: flex;
        justify-content:center;
        align-items:center;
    }
    .sortMenu .all:before{
        content: '';
        height: 25px;
        width: 1px;
        position: absolute;
        box-shadow: 1px 0px 1px #e0e0e0;
        left: 0px;
    }
    .sortMenu .all img{
        display: block;
        width: 16px;
    }
    .sortMenu .pull-down{
        position: absolute;
        top: 40px;
        height:auto;
        font-size: 0.25rem;
        width: 100%;
        background: #fff;
        z-index: 1;
        border-top: 1px solid #f2f2f2;

    }
    .pull-down-sort{
        width: 100%;
        display: flex;
        justify-content: flex-start;
        align-items: center;
        align-content: space-around;
        flex-wrap: wrap;
        flex-direction: row
    }
    .pull-down-sort li{
        float: left;
        padding: .1rem 0 .1rem .3rem;
        width: 2.5rem;
        /*border-bottom: 1px solid #f2f2f2;*/

    }
    .pull-down-sort li a:hover{
        color: #ff474c;
    }
</style>
